package com.yf.controller;

import com.yf.bean.*;
import com.yf.service.impl.YfjxServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author : hzyao
 * @date : 16:29 2020/10/7
 */
@Controller
@RequestMapping("yf")
public class yfljxController {
    @Autowired
    private YfjxServiceImpl yfservice;

    @RequestMapping("/getBy8")
    public String getByLevel8(@Param("ch8") String ch8, Model model){

        List<yfjx8> jx8 = yfservice.getByLevel8(ch8);
        if (jx8 != null && !jx8.isEmpty()){
            model.addAttribute("jx8",jx8);
            return "yfmain";
        }else {
            model.addAttribute("error","不存在的翅号！请输入正确的翅号，或者选择正确的家系！");
            return "error";
        }

    }
    @RequestMapping("/tomain")
    public String toyfmain(){

        return "yfmain";
    }
    //YF8代数据查询
    @RequestMapping("/getBy8/{lh8}")
    @ResponseBody
    public yfjx8 getByLevel8(@PathVariable("lh8") String lh8){
        return yfservice.getByLevel7(lh8);
    }
//    7代
    @RequestMapping("/getBy7/{lh7}")
    @ResponseBody
    public yfjx7 getByLevel7(@PathVariable("lh7") String lh7){
        return yfservice.getByLevel6(lh7);
    }
//6代
    @RequestMapping("/getBy6/{lh6}")
    @ResponseBody
    public yfjx6 getByLevel6(@PathVariable("lh6") String lh6){
        return yfservice.getByLevel5(lh6);
    }
//5代
    @RequestMapping("/getBy5/{lh5}")
    @ResponseBody
    public yfjx5 getByLevel5(@PathVariable("lh5") String lh5){
        return yfservice.getByLevel4(lh5);
    }

    //4代
    @RequestMapping("/getBy4/{lh4}")
    @ResponseBody
    public yfjx4 getByLevel4(@PathVariable("lh4") String lh4){
        return yfservice.getByLevel3(lh4);
    }
}
